#coding=utf-8
import subprocess, re

def check_running_proxy():
    result = {'http':[]}
    
    command = 'ps aux|grep proxy.py|grep -v grep'
    r = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).communicate()[0]
    data = [re.split(r'\s+', i) for i in r.split('\n') if i]
    
    for d in data:
        #print d
        if d[-5] == 'reverse':
            result['revervse'] = [ d[-3], d[-5], d[-1], d[1] ]
        else:
            result['http'].append([ d[-3], d[-5], d[-1], d[1] ])
      
    return result

def stop_proxy(pid):
    subprocess.Popen(['kill', pid])
    
if __name__ == '__main__':
    print check_running_proxy()
